<template>
	<view class="page-height">
		<image src="@/static/images/login-bg.png" class="bg"></image>
		<view class="page-content">
			<image src="@/static/images/logo02.png" class="logo"></image>

			<view class="form-view">
				<text class="title">您好，欢迎登录</text>

				<view class="col">
					<view class="item">
						<text class="label">手机号</text>
						<view class="line">
							<view class="input-bg">
								<input type="text" v-model="mobile" placeholder="请输入手机号" class="input" />
							</view>
						</view>
					</view>
					<view class="item">
						<text class="label">密码</text>
						<view class="line">
							<view class="input-bg">
								<input type="password" v-model="password" placeholder="请输入密码" class="input" />
							</view>
						</view>
					</view>
					<view class="item">
						<text class="label">验证码</text>
						<view class="line">
							<view class="input-bg">
								<input type="text" v-model="code" placeholder="请输入验证码" class="input" />
							</view>
							<i-captcha class="code-img" @success="(e) => uniqid = e"></i-captcha>
							<!-- <image src="@/static/images/img-code.png" mode="aspectFill" class="code-img"></image> -->
						</view>
					</view>
				</view>

				<button class="btn" @click="onLogin()">登 录</button>

				<view class="phone-login" @click="openWin('/pages/login/login-phone')">
					<image src="@/static/images/phone-login.png" class="ioc"></image>
					<text class="text">手机号登录</text>
				</view>
				<view class="reg-btn" @click="openWin('/pages/login/reg')">
					<text class="reg-text">注册</text>
					<image src="@/static/images/reg-ioc.png" class="ioc"></image>
				</view>
			</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				uniqid: "",
				mobile: "",
				password: "",
				code: "",
			};
		},



		methods: {
			onLogin() {
				if (!this.mobile) return this.fail("请输入手机号")
				if (!this.password) return this.fail("请输入密码")
				if (!this.code) return this.fail("请输入验证码")

				const params = {
					account: this.mobile,
					password: this.password,
					login: this.uniqid,
					code: this.code,
				}
				this.api.post("/api/user/login", { params: params }).then(res => {
					const token = res.userinfo.token
					this.$store.commit('login', token)
					this.getUserInfo();
					uni.showToast({
						title: "登录成功"
					})
					setTimeout(() => {
						uni.switchTab({
							url: "/pages/home/index"
						})
					}, 1000)
				}).catch(err => {
					this.apiErr(err)
				}).finally(() => {
					this.loadingHide();
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-height {
		background: #ffffff;
	}

	.page-content {
		display: flex;
		flex-direction: column;
		position: relative;
		z-index: 1;
		padding-bottom: 30rpx;

	}

	.bg {
		width: 750rpx;
		height: 436rpx;
		position: fixed;
		top: 0;
		left: 0;
		z-index: 0;
	}

	.logo {
		max-width: 180rpx;
		max-height: 180rpx;

		margin: 110rpx auto 0;
	}

	.form-view {
		display: flex;
		flex-direction: column;
		background-color: #ffffff;
		border-radius: 30rpx 30rpx 0rpx 0rpx;
		margin-top: 60rpx;
		padding: 0 70rpx;

		.title {
			font-size: 42rpx;
			color: #333333;
			margin-top: 54rpx;
		}

		.col {
			display: flex;
			flex-direction: column;

			.item {
				display: flex;
				flex-direction: column;

				.label {
					font-size: 32rpx;
					color: #333333;
					margin-top: 32rpx;
				}

				.line {
					display: flex;
					align-items: center;
					margin-top: 20rpx;

					.input-bg {
						height: 98rpx;
						border-radius: 100px;
						flex: 1;
						background: #F7F8FA;
						border-radius: 100px;
						display: flex;
						align-items: center;
						padding: 0 32rpx;

						.input {
							flex: 1;
						}
					}

					.code-img {
						width: 220rpx;
						height: 98rpx;
						border-radius: 100px;
						margin-left: 24rpx;
					}
				}
			}
		}
	}

	.btn {
		margin-top: 50rpx;
	}

	.phone-login {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 44rpx;

		.ioc {
			width: 70rpx;
			height: 70rpx;
		}

		.text {
			font-size: 28rpx;
			color: #333333;
			margin-top: 10rpx;
		}
	}

	.reg-btn {
		display: flex;
		align-items: center;
		margin-left: auto;
		margin-top: 4rpx;
		height: 74rpx;
		padding: 0 30rpx;
		border-radius: 100px;
		background-color: #55C29A;

		.reg-text {
			font-size: 32rpx;
			color: #FFFFFF;
		}

		.ioc {
			width: 34rpx;
			height: 34rpx;
			margin-left: 10rpx;
		}


	}
</style>